package com.stylefeng.guns.modular.goods.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.goods.model.SpecValue;
import com.stylefeng.guns.modular.goods.service.ISpecValueService;

/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2018-09-05 16:10:16
 */
@Controller
@RequestMapping("/specValue")
public class SpecValueController extends BaseController {

    private String PREFIX = "/goods/specValue/";

    @Autowired
    private ISpecValueService specValueService;

    /**
     * 跳转到首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "specValue.html";
    }

    /**
     * 跳转到添加
     */
    @RequestMapping("/specValue_add")
    public String specValueAdd() {
        return PREFIX + "specValue_add.html";
    }

    /**
     * 跳转到修改
     */
    @RequestMapping("/specValue_update/{specValueId}")
    public String specValueUpdate(@PathVariable Long specValueId, Model model) {
        SpecValue specValue = specValueService.selectById(specValueId);
        model.addAttribute("item",specValue);
        LogObjectHolder.me().set(specValue);
        return PREFIX + "specValue_edit.html";
    }

    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return specValueService.selectList(null);
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(SpecValue specValue) {
        specValueService.insert(specValue);
        return SUCCESS_TIP;
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Long specValueId) {
        specValueService.deleteById(specValueId);
        return SUCCESS_TIP;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(SpecValue specValue) {
        specValueService.updateById(specValue);
        return SUCCESS_TIP;
    }

    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{specValueId}")
    @ResponseBody
    public Object detail(@PathVariable("specValueId") Long specValueId) {
        return specValueService.selectById(specValueId);
    }
}
